//
//  SRCurrentTask+SR.m
//  SportRing
//
//  Created by mykoma on 14/10/27.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRCurrentTask+Cate.h"


@implementation SRCurrentTask (Cate)

+ (SRCurrentTask *)currentTaskForMe:(SRMe *)me
{
    __block SRCurrentTask * task = nil;
    [MagicalRecord saveUsingCurrentThreadContextWithBlockAndWait:^(NSManagedObjectContext *localContext)
     {
         task = [SRCurrentTask MR_createEntity];
         task.current = [SRCurrent findCurrentCINEForMe:me];
     }];
    return task;
}

- (void)configAttributesWithBlock:(void(^)(SRCurrentTask * aSelf))block
{
    [MagicalRecord saveUsingCurrentThreadContextWithBlockAndWait:^(NSManagedObjectContext *localContext)
     {
         block(self);
     }];
}

@end

@implementation SRCurrentTask (Find)

+ (SRCurrentTask *)findCurrentTaskForMe:(SRMe *)me
{
    return me.current.task;
}

+ (SRCurrentTask *)findCurrentTaskCINEForMe:(SRMe *)me
{
    SRCurrentTask * currentTask = [SRCurrentTask findCurrentTaskForMe:me];
    if (currentTask == nil) {
        currentTask = [SRCurrentTask currentTaskForMe:me];
    }
    return currentTask;
}

@end